home *** CD-ROM | disk | FTP | other *** search
- /* Fingerd IDLEINWORDS PROC */
- /* written by Stuart Cheshire <cheshire@cs.stanford.edu> */
- /* */
- /* To compile using Think C: */
- /* Create a new project and add only this file to it (Source menu) */
- /* Set Project Type (Project menu) to: */
- /* Code Resource */
- /* File Type: rsrc */
- /* Creator: RSED */
- /* DO NOT check Multi-Segment */
- /* Name: IDLEINWORDS */
- /* Type: PROC */
- /* ID: 139 */
- /* DO NOT check Custom Header */
- /* Attrs: 20 (Purgeable) */
- /* */
- /* Build Code Resource (Project menu) and save the file as */
- /* “IDLEINWORDS.rsrc”. You can now double-click the file produced */
- /* to open it in ResEdit, from where you can copy and paste the */
- /* PROC resource into your “Finger Preferences” file. To make your */
- /* own token, change the name of the PROC resource and change the */
- /* ID to be above 1000 to ensure that it does not clash with the */
- /* ID of any pre-defined token. */
- /* */
- /* Note that “main” MUST be declared “pascal void” in order to work.*/
-
- typedef struct
- {
- StringPtr fingeredname; // In - name the caller specified
- StringPtr param; // In - parameter following special token
- StringPtr returnvalue; // Out - return string, to be appended to finger output. Don't change ptr!
- Handle fingeroutput; // I/O - Handle to finger output as it’s built.
- long hlength; // I/O - handle length.
- long offset; // I/O - offset from start of handle that finger output is up to
- long idle; // In - Idle time in seconds
- long remoteIP; // In - IP address of fingerer
- Boolean expandtokens; // Out - Expand <cr>s and %tokens inserted into the fingeroutput handle
- } parameterRecord;
-
- #define MINUTE 60
- #define HOUR (MINUTE*60)
- #define DAY (HOUR*24L)
-
- static void Pstr(StringPtr dest, StringPtr src)
- {
- unsigned char *ptr = dest + 1 + *dest;
- unsigned char len = *src++;
- *dest += len;
- while (len--) *ptr++ = *src++;
- }
-
- static void Pnum(StringPtr dest, short number)
- {
- if (number > 9) Pnum(dest, number / 10);
- *(dest + ++(*dest)) = number % 10 + '0';
- }
-
- static void Ppair(StringPtr dest, short n1, StringPtr s1, short n2, StringPtr s2)
- {
- if (n1)
- {
- Pnum(dest, n1);
- Pstr(dest, s1);
- if (n1>1) Pstr(dest, "\ps");
- Pstr(dest, "\p ");
- }
- Pnum(dest, n2);
- Pstr(dest, s2);
- if (n2>1) Pstr(dest, "\ps");
- }
-
- pascal void main(parameterRecord *p)
- {
- long i = p->idle;
- *p->returnvalue = 0; /* set initial length of result string to zero */
- if (i == 0) Pstr (p->returnvalue, "\pNo");
- else if (i < HOUR) Ppair(p->returnvalue, i/MINUTE, "\p minute", (i%MINUTE), "\p second");
- else if (i < DAY ) Ppair(p->returnvalue, i/HOUR, "\p hour", (i%HOUR)/MINUTE, "\p minute");
- else Ppair(p->returnvalue, i/DAY, "\p day", (i%DAY) /HOUR, "\p hour" );
- }
-
-